package utils

// Reverse 将s反序
func Reverse(s []byte) []byte {
	k := make([]byte, len(s))
	copy(k, s)
	for i, j := 0, len(k)-1; i < j; i, j = i+1, j-1 {
		k[i], k[j] = k[j], k[i]
	}
	return k
}

// RemoveDuplicatesAndEmpty 剔除空数组和重复的数组
func RemoveDuplicatesAndEmpty(slc []string) []string {
	result := []string{} // 存放结果
	for i := range slc {
		flag := true
		if slc[i] == `` {
			continue
		}
		for j := range result {
			if slc[i] == result[j] {
				flag = false // 存在重复元素，标识为false
				break
			}
		}
		if flag { // 标识为false，不添加进结果
			result = append(result, slc[i])
		}
	}
	return result
}

// RemoveEmpty 剔除空数组
func RemoveEmpty(a []string) (ret []string) {
	alen := len(a)
	for i := 0; i < alen; i++ {
		if len(a[i]) == 0 {
			continue
		}
		ret = append(ret, a[i])
	}
	return
}
